package org.demo.algorithm.lagou.column.relearn;

/**
 * 字符串匹配
 */
public class StringIndexOf {

    public boolean indexOf(String main, String pattern) {
        for (int i = 0; i < main.length() - pattern.length() + 1; i++) {
            if (main.charAt(i) == pattern.charAt(0)) {
                int jc = 0;
                for (int j = 1; j < pattern.length(); j++) {
                    if (main.charAt(i + j) != pattern.charAt(j)) {
                        break;
                    }
                    jc = j;
                }
                if (jc == pattern.length() - 1) {
                    return true;
                }
            }
        }
        return false;
    }

}
